<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="报表名称" prop="rptName">
        <el-input
          v-model="queryParams.rptName"
          placeholder="请输入报表名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="记录时间" prop="rptTime">
        <el-date-picker :editable="false" clearable size="small" v-model="queryParams.rptTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核人" prop="auditor">
        <el-input v-model="queryParams.auditor" placeholder="请输入审核人" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="操作人" prop="operator">
        <UserDialog @dialogChange="queryParams.operator = $event.label" :echoValue="queryParams.operator" placeholder="请选择人员" />
        <!-- <el-input
          v-model="queryParams.operator"
          placeholder="请输入操作人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        /> -->
        <!--<el-select
          v-model="queryParams.operator"
          filterable
          allow-create
          placeholder="请选择操作人"
          style="width: 100%"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in userList"
            :key="item.nickName"
            :label="item.nickName"
            :value="item.nickName"
          ></el-option>
        </el-select>-->
      </el-form-item>
      <!--  <el-form-item label="报表编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入报表编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="工厂名称" prop="factory">
        <el-input
          v-model="queryParams.factory"
          placeholder="请输入工厂名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备类型" prop="rptType">
        <el-select v-model="queryParams.rptType" placeholder="请选择设备类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['report:arrange:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['report:arrange:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['report:arrange:remove']">删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['report:arrange:export']"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-s-check" size="mini" :disabled="multiple" @click="handleCheck" v-hasPermi="['report:arrange:check']">审核</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="arrangeList" @selection-change="handleSelectionChange" max-height="550">
      <el-table-column type="selection" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <!-- <el-table-column label="报表名称" align="center" prop="rptName" /> -->
      <el-table-column label="记录时间" align="center" prop="rptTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rptTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>

      <el-table-column label="报表编码" align="center" prop="code" min-width="140px" />
      <el-table-column label="工厂名称" align="center" prop="factory" min-width="140px" />
      <el-table-column label="设备类型" align="center" prop="rptType" />

      <el-table-column label="操作人" align="center" prop="operator" />
      <el-table-column label="审核人" align="center" prop="auditor" width="60px" />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="250px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="excelhandleView(scope.row)">导出</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['report:arrange:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>

          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['report:arrange:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改理坯机运行记录对话框 -->
    <el-dialog fullscreen :title="title" :visible.sync="open" width="900px" append-to-body custom-class="myDialog">
      <TableHeader @nameChange="nameChange" @nameChange2="nameChange2" :data="{
          mainTitle: '理坯机运行记录',
          company: form.factory,
          code: form.code,
        }" />
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <!-- <el-col :span="12">
                <el-form-item label="报表名称" prop="rptName">
                  <el-input v-model="form.rptName" placeholder="请输入报表名称" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <el-col :span="12">
            <el-form-item label="记录时间" prop="rptTime">
              <el-date-picker :editable="false" clearable size="small" v-model="form.rptTime" type="date" value-format="yyyy-MM-dd" placeholder="选择记录时间" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <!-- <el-col :span="12">
                <el-form-item label="报表编码" prop="code">
                  <el-input v-model="form.code" placeholder="请输入报表编码" :disabled="openDisabled" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="工厂名称" prop="factory">
                  <el-input v-model="form.factory" placeholder="请输入工厂名称" :disabled="openDisabled" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="设备类型" prop="rptType">
                  <el-select v-model="form.rptType" placeholder="请选择设备类型" :disabled="openDisabled">
                    <el-option label="请选择字典生成" value="" />
                  </el-select>
                </el-form-item>
            </el-col> -->
        </el-row>

        <!-- 理坯机运行记录1信息 -->
        <br />
        <el-divider content-position="center">理坯机使用信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddRptProArrangesub1" :disabled="openDisabled">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteRptProArrangesub1" :disabled="openDisabled">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-upload2" size="mini" @click="$refs.rptProArrangesub1.bodyWrapper.scrollTop=0">置顶</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-download" size="mini" @click="$refs.rptProArrangesub1.bodyWrapper.scrollTop=$refs.rptProArrangesub1.bodyWrapper.scrollHeight">置底</el-button>
          </el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-table :data="rptProArrangesub1List" :row-class-name="rowRptProArrangesub1Index" @selection-change="handleRptProArrangesub1SelectionChange" ref="rptProArrangesub1" maxHeight="500">
          <el-table-column type="selection" width="50" align="center" fixed />
          <!-- <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          /> -->
          <el-table-column label="供应商" prop="gys" width="350" fixed>
            <template slot-scope="scope">
              <!-- <treeselect
                :searchable="false"
                v-model="scope.row.gys"
                :options="deptOptions"
                zIndex="9999"
                :appendToBody="true"
                :normalizer="normalizer"
                placeholder="请选择设备厂家"
              /> -->
              <ReportDialog @dialogChange="scope.row.gys = $event.value" :echoValue="scope.row.gys" :dialogData="eqpfactoryList" value="id" label="label" placeholder="选择设备厂家" :openDisabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="规格" prop="gg" minWidth="200" fixed>
            <template slot-scope="scope">
              <!-- <el-input v-model="scope.row.gg" placeholder="请输入规格" :disabled="openDisabled"/> -->
              <Dialog @dialogChange="dialogChange($event, scope)" :echoValue="scope.row.ggname" parameter="rows" value="id" label="name" :multiple="false" search="name/code" url="/basic/productInfo/listSelectBZ" :column="['物料编号/code', '物料名称/name']" placeholder="请选择内容" :axiosData="{typeCode: 'BZCL' }" :openDisabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="投坯时间" prop="tpsj" minWidth="150">
            <template slot-scope="scope">
              <el-time-picker :editable="false" clearable v-model="scope.row.tpsj" value-format="HH:mm" format="HH:mm" placeholder="选择投坯时间" :disabled="openDisabled">
              </el-time-picker>
            </template>
          </el-table-column>
          <el-table-column label="数量（只）" prop="shuliang" minWidth="120">
            <template slot-scope="scope">
              <el-input type="number" v-model="scope.row.shuliang" placeholder="请输入数量" :disabled="openDisabled" @input="datacala($event)" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" />
            </template>
          </el-table-column>
          <el-table-column label="生产日期" prop="scrq" minWidth="140">
            <template slot-scope="scope">
              <el-date-picker :editable="false" clearable v-model="scope.row.scrq" type="date" value-format="yyyy-MM-dd" placeholder="选择生产日期" :disabled="openDisabled" @change="autoDate2(scope)">
              </el-date-picker>
            </template>
          </el-table-column>
          <el-table-column label="序号" prop="xh" minWidth="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.xh" placeholder="请输入序号" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="使用前检查情况" prop="syqjcqk" minWidth="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.syqjcqk" :disabled="openDisabled">
                <el-option value="正常">正常</el-option>
                <el-option value="异常">异常</el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="巡检确认" prop="xjqr" minWidth="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.xjqr" placeholder="请输入巡检确认" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <!-- <el-table-column label="热熔胶型号" prop="rrjxh">
            <template slot-scope="scope">
                <el-input v-model="scope.row.rrjxh" placeholder="请输入热熔胶型号" :disabled="openDisabled"/>
            </template>
          </el-table-column>
          <el-table-column label="热熔胶领用量" prop="rrjlyl">
            <template slot-scope="scope">
                <el-input v-model="scope.row.rrjlyl" placeholder="请输入热熔胶领用量" :disabled="openDisabled"/>
            </template>
          </el-table-column>
          <el-table-column label="热熔胶剩余量" prop="rrjleft">
            <template slot-scope="scope">
                <el-input v-model="scope.row.rrjleft" placeholder="请输入热熔胶剩余量" :disabled="openDisabled"/>
            </template>
          </el-table-column>
          <el-table-column label="热熔胶使用量" prop="rrjsyl">
            <template slot-scope="scope">
                <el-input v-model="scope.row.rrjsyl" placeholder="请输入热熔胶使用量" :disabled="openDisabled"/>
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
                <el-input v-model="scope.row.remark" type="textarea" placeholder="请输入内容" :disabled="openDisabled"/>
            </template>
          </el-table-column> -->
        </el-table>
        <br />
        <el-divider content-position="center">理坯机运行记录信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddRptProArrangesub2" :disabled="openDisabled">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteRptProArrangesub2" :disabled="openDisabled">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-upload2" size="mini" @click="$refs.rptProArrangesub2.bodyWrapper.scrollTop=0">置顶</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-download" size="mini" @click="$refs.rptProArrangesub2.bodyWrapper.scrollTop=$refs.rptProArrangesub2.bodyWrapper.scrollHeight">置底</el-button>
          </el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-table maxHeight="500" :data="rptProArrangesub2List" :row-class-name="rowRptProArrangesub2Index" @selection-change="handleRptProArrangesub2SelectionChange" ref="rptProArrangesub2">
          <el-table-column type="selection" minWidth="50" align="center" />
          <!-- <el-table-column
            label="序号"
            align="center"
            prop="index"
            minWidth="50"
          /> -->
          <el-table-column label="不合格坯数量" prop="bhgsl">
            <template slot-scope="scope">
              <el-input v-model="scope.row.bhgsl" placeholder="请输入不合格坯数量"  @input="datacala($event)" :disabled="openDisabled" type="number" />
            </template>
          </el-table-column>
          <el-table-column label="不合格原因" prop="bhgyy">
            <template slot-scope="scope">
              <el-input v-model="scope.row.bhgyy" placeholder="请输入不合格原因" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark" placeholder="请输入内容" :disabled="openDisabled" />
            </template>
          </el-table-column>
        </el-table>

        <!-- 审核 -->
        <el-col :span="24">
          <el-form-item label-width="250px" label="投坯总量（多少行就是多少笼）">
            <el-input type="number" v-model="form.tpzl1" :disabled="openDisabled" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label-width="250px" label="投坯总量（所有行数量和）">
            <el-input type="number" v-model="form.tpzl2" :disabled="openDisabled" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label-width="250px" label="投坯使用量（投坯总量-不合格数量）">
            <el-input type="number" v-model="form.tpzl3" :disabled="openDisabled" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label-width="250px" label="其它保养记录" prop="otherby">
            <el-input v-model="form.otherby" type="textarea" placeholder="请输入内容" :disabled="openDisabled" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label-width="250px" label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="openDisabled" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label-width="250px" label="审核人" prop="auditor">
            <el-input v-model="form.auditor" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="操作人" prop="operator">
            <UserDialog @dialogChange="form.operator = $event.label" :echoValue="form.operator" :multiple="false" :openDisabled="openDisabled" placeholder="请选择人员" />
            <!-- <el-input
              v-model="form.operator"
              placeholder="请输入操作人"
              :disabled="openDisabled"
            /> -->
            <!--<el-select
              v-model="form.operator"
              filterable
              allow-create
              placeholder="请选择操作人"
              style="width: 100%"
              :disabled="openDisabled"
            >
              <el-option
                v-for="item in userList"
                :key="item.nickName"
                :label="item.nickName"
                :value="item.nickName"
              ></el-option>
            </el-select>-->
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listArrange,
  getArrange,
  delArrange,
  addArrange,
  updateArrange,
  checkArrange,
} from "@/api/report/process/arrange";
import { getInfo } from "@/api/login";
import { listUser } from "@/api/system/user";
import { listEqpfactory } from "@/api/basic/eqpfactory/eqpfactory";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listSelect2 } from "@/api/report/process/label";

export default {
  name: "Arrange",
  components: { Treeselect },
  data() {
    return {
      /* 当前用户名 */
      nickName: "",
      userList: [],
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedRptProArrangesub1: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      yflType: null,
      // 总条数
      total: 0,
      // 树选项
      deptOptions: [],
      // 理坯机运行记录表格数据
      arrangeList: [],
      // 理坯机运行记录1表格数据
      rptProArrangesub1List: [],
      rptProArrangesub2List: [],
      tpzl1: 0,
      tpzl2: 0,
      tpzl3: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        rptName: null,
        rptTime: null,
        rptTime1: null,
        auditor: null,
        operator: null,
        code: null,
        factory: null,
        rptType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      scrq: null,
      //供应商列表
      eqpfactoryList: [],
    };
  },
  created() {
    this.getList();
    /** 查询供应商列表 */
    this.getEqpfactory();
    this.queryUserList();
    this.getConfigKey("yfl_type").then((response) => {
      this.yflType = response.msg;
    });
  },
  methods: {
    autoDate2(scope) {
      this.scrq = scope.row.scrq;
    },
    /** 查询供应商列表 */
    getEqpfactory() {
      listSelect2().then((response) => {
        this.eqpfactoryList = response.rows;
      });
    },
    /** 查询理坯机运行记录列表 */
    getList() {
      this.loading = true;
      listArrange(this.queryParams).then((response) => {
        this.arrangeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rptName: null,
        rptTime: null,
        auditor: null,
        operator: this.nickName,
        code: "LK-QF-LS1-10-012-11-01",
        factory: "青岛崂山矿泉水有限公司",
        rptType: "理坯机",
        delFlag: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        tpzl1: null,
        tpzl2: null,
        tpzl3: null,
      };
      this.rptProArrangesub1List = [];
      this.rptProArrangesub2List = [];
      this.resetForm("form");

      const myDate = new Date();
      const year = myDate.getFullYear();
      const month = myDate.getMonth() + 1;
      const day = myDate.getDate();
      this.form.rptTime = `${year}-${month}-${day}`;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.rptTime != null) {
        let arr = this.queryParams.rptTime;
        this.queryParams.rptTime = arr[0];
        this.queryParams.rptTime1 = arr[1];
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openDisabled = false;
      this.open = true;
      this.title = "添加理坯机运行记录";
    },
    dialogChange(event, scope) {
      // // console.log(scope);
      //  //选择后续操作
      // if (event.options instanceof Array == true) {
      //   this.rptProArrangesub1List.splice(scope.$index, 1, ...event.options);
      // } else {
      //   this.rptProArrangesub1List[scope.$index].gg = event.options;
      // }
      // this.rptProArrangesub1List.push({});
      // this.rptProArrangesub1List.pop();
      // console.log(event);

      this.rptProArrangesub1List[scope.$index].gg = event.options.code;
      this.rptProArrangesub1List[scope.$index].ggname = event.label;
      // console.log(this.rptProArrangesub1List)
    },
    dialogChangeFactory(event, scope) {
      this.rptProArrangesub1List[scope.$index].gys = event.value;
      this.rptProArrangesub1List[scope.$index].gysname = event.label;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      getArrange(id).then((response) => {
        this.form = response.data;
        this.rptProArrangesub1List = response.data.rptProArrangesub1List;
        this.rptProArrangesub2List = response.data.rptProArrangesub2List;
        /*   // this.tpzl1=String(this.rptProArrangesub1List.length);
           //数量1
           this.form.tpzl1 = this.rptProArrangesub1List.length.toString();
           //数量2
           let sum = 0;
           for (let i = 0; i < this.rptProArrangesub1List.length; i++) {
             sum += this.rptProArrangesub1List[i].shuliang;
           }
           this.form.tpzl2 = String(sum);
           //不合格数量2
           let sum2 = 0;
           for (let i = 0; i < this.rptProArrangesub2List.length; i++) {
             let temp = this.rptProArrangesub2List[i].bhgsl;
             sum2 += parseInt(temp);
           }
           this.form.tpzl3 = String(sum - sum2);*/

        this.open = true;
        this.title = "修改理坯机运行记录";
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;
      const id = row.id || this.ids;
      getArrange(id).then((response) => {
        this.form = response.data;
        this.rptProArrangesub1List = response.data.rptProArrangesub1List;
        this.rptProArrangesub2List = response.data.rptProArrangesub2List;
        //  console.log(this.rptProArrangesub1List);
        //数量1
        this.form.tpzl1 = String(this.rptProArrangesub1List.length);
        //数量2
        let sum = 0;
        for (let i = 0; i < this.rptProArrangesub1List.length; i++) {
          sum += this.rptProArrangesub1List[i].shuliang;
        }
        this.form.tpzl2 = String(sum);
        //不合格数量2
        let sum2 = 0;
        for (let i = 0; i < this.rptProArrangesub2List.length; i++) {
          let temp = this.rptProArrangesub2List[i].bhgsl;
          sum2 += parseInt(temp);
        }
        this.form.tpzl3 = String(sum - sum2);
        this.open = true;
        this.title = "查看理坯机运行记录";
      });
    },
    datacala(val){
 // this.rptProArrangesub1List = response.data.rptProArrangesub1List;
 // this.rptProArrangesub2List = response.data.rptProArrangesub2List;
  //  console.log(this.rptProArrangesub1List);
  //数量1
  this.form.tpzl1 = String(this.rptProArrangesub1List.length);
  //数量2
  let sum = 0;
  for (let i = 0; i < this.rptProArrangesub1List.length; i++) {
    let temp = this.rptProArrangesub1List[i].shuliang;
    if(temp!=null&&temp!="")
    {
      sum += parseInt(temp);
    }

  }
  this.form.tpzl2 = String(sum);
  //不合格数量2
  let sum2 = 0;
  for (let i = 0; i < this.rptProArrangesub2List.length; i++) {
    let temp = this.rptProArrangesub2List[i].bhgsl;
    if(temp!=null&&temp!="")
    {
      sum2 += parseInt(temp);
    }

  }
  this.form.tpzl3 = String(sum - sum2);
},
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.rptProArrangesub1List = this.rptProArrangesub1List;
          this.form.rptProArrangesub2List = this.rptProArrangesub2List;
          if (this.form.id != null) {
            updateArrange(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            const rLoading = this.openLoading();
            addArrange(this.form)
              .then((response) => {
                this.msgSuccess("新增成功");
                this.open = false;
                rLoading.close();
                this.getList();
              })
              .catch((error) => {
                rLoading.close();
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除理坯机运行记录编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delArrange(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 理坯机运行记录1序号 */
    rowRptProArrangesub1Index({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 理坯机理坯机使用信息1添加按钮操作 */
    handleAddRptProArrangesub1() {
      let l = this.rptProArrangesub1List.length;
      let gys = null;
      let gg = "";
      let ggname = "";
      if (l > 0) {
        gys = this.rptProArrangesub1List[l - 1].gys;
        gg = this.rptProArrangesub1List[l - 1].gg;
        ggname = this.rptProArrangesub1List[l - 1].ggname;
      }

      let obj = {};
      obj.gys = gys;
      obj.gysname = "";
      obj.gg = gg;
      obj.ggname = ggname;
      obj.tpsj = "";
      obj.shuliang = "";
      obj.scrq = this.scrq;
      obj.xh = "";
      obj.syqjcqk = "正常";
      obj.xjqr = "";
      obj.rrjxh = "";
      obj.rrjlyl = "";
      obj.rrjleft = "";
      obj.rrjsyl = "";
      obj.remark = "";
      this.rptProArrangesub1List.push(obj);
     this.datacala();
      listEqpfactory().then((response) => {
        this.deptOptions = this.handleTree(response.data, "id");
      });
    },
    /** 转换数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      };
    },
    /** 理坯机运行记录1删除按钮操作 */
    handleDeleteRptProArrangesub1() {
      if (this.checkedRptProArrangesub1.length == 0) {
        this.$alert("请先选择要删除的理坯机运行记录1数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.rptProArrangesub1List.splice(
          this.checkedRptProArrangesub1[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handleRptProArrangesub1SelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.rptProArrangesub1.clearSelection();
        this.$refs.rptProArrangesub1.toggleRowSelection(selection.pop());
      } else {
        this.checkedRptProArrangesub1 = selection;
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "report/arrange/export",
        {
          ...this.queryParams,
        },
        "理坯机运行记录" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    excelhandleView(row) {
      this.download(
        "Laboratory/arrange/exportexcel?id=" + row.id,
        {
          ...this.queryParams,
        },
        "理坯机运行记录" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    /** 理坯机运行记录2序号 */
    rowRptProArrangesub2Index({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 理坯机运行记录2添加按钮操作 */
    handleAddRptProArrangesub2() {
      let obj = {};
      obj.bhgsl = "";
      obj.bhgyy = "";
      obj.remark = "";
      this.rptProArrangesub2List.push(obj);
      this.datacala();
    },
    /** 理坯机运行记录2删除按钮操作 */
    handleDeleteRptProArrangesub2() {
      if (this.checkedRptProArrangesub2.length == 0) {
        this.$alert("请先选择要删除的理坯机运行记录2数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.rptProArrangesub2List.splice(
          this.checkedRptProArrangesub2[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handleRptProArrangesub2SelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.rptProArrangesub2.clearSelection();
        this.$refs.rptProArrangesub2.toggleRowSelection(selection.pop());
      } else {
        this.checkedRptProArrangesub2 = selection;
      }
    },
    //接收编号
    nameChange(e) {
      this.form.code = e;
    },
    nameChange2(e) {
      this.form.factory = e;
    },
    /** 审核按钮操作 */
    handleCheck(row) {
      /* 审核 */
      this.ids.forEach((id) => {
        getArrange(id).then((response) => {
          if (response.data.auditor != null && response.data.auditor != "") {
            this.msgError(
              '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
            );
          } else {
            let obj = {};
            obj.id = id;
            obj.auditor = this.nickName;
            obj.rptProArrangesub1List = this.rptProArrangesub1List;
            obj.rptProArrangesub2List = this.rptProArrangesub2List;
            /* 修改 */
            checkArrange(obj).then((response) => {
              this.msgSuccess('编号为"' + id + '"的数据项审核成功！');
              this.getList();
            });
          }
        });
      });
    },
    /* 查询用户列表 */
    queryUserList() {
      listUser().then((response) => {
        this.userList = response.rows;
      });
      getInfo().then((response) => {
        this.nickName = response.user.nickName;
      });
    },
  },
};
</script>
